/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * Copyright @2008 the original author or authors.
 */
package com.bluestone.action;

import com.bluestone.BaseAction;
import com.bluestone.config.ConfigUtil;
import com.bluestone.scripts.ActionScript;
import com.bluestone.util.Util;

/**
 * @author <a href="mailto:bluestone.daniel.q@gmail.com">daniel.q</a>
 * 
 */
public class ActionFactory {
	public static String MOVEACTION = "move";

	public static String DELAYACTION = "delay";

	public static String CLICKACTION = "click";

	public static String INPUTTEXTACTION = "inputtext";

	public static String INPUTKEYACTION = "inputkey";

	public static String MAXPAGEACTION = "maxpage";

	public static String CLOSEPAGEACTION = "closepage";

	public static String RUNACTION = "run";

	public static String SELECTLISTACTION = "selectlist";

	public static String CHECKTRUEACTION = "checktrue";

	public static String CHECKFALSEACTION = "checkfalse";

	public static String WINRUNACTION = "winrun";

	public static String FOCUSACTION = "focus";
	public static String SAVEASACTION="saveAs";
	public static String COMPAREIMAGEACTION="compareImage";
	public static String BACKPAGEACTION="backpage";
	public static String CHECKRGBACTION="checkrgb";
	public static String CHECKBROWSERACTION ="checkbrowser";
	
	public static String MINPAGEACTION = "minpage";
	
	public static String RESETKEYSACTION = "resetkeys";
	
	public static String CLOSEALLPAGESACTION = "closeallpages";
	
	public static String CALLFUNCTIONACTION = "callfunction";
	
	public static String OPENURLACTION = "openurl";
	
	public static String SETCURRENTPAGEACTION = "setcurrentpage";
	
	public static String OPENPAGEACTION = "openpage";
	
	public static String CLOSECURRENTPAGEACTION = "closecurrentpage";
	
	public static String REMOVECURRENTPAGEACTION = "removecurrentpage";
	
	public static String NEXTFOCUSACTION = "nextfocus";
	
	public static String SCREENSHOTACTION = "screenshot";
	
	public static String SAVEASIMAGEACTION = "saveasimage";
	
	public static String SAVEASFILEACTION = "saveasfile";
	
	public static String ROBOTACTION = "robot";
	
	public static String INTERCEPTACTION = "intercept";
	
	public static String CHECKPROJECTACTION = "checkproject";
	
	public static String CLOSEALLWINDOWSACTION = "closeallwindows";	
	
	public static String STARTSERVERACTION = "startserver";
	
	public static String STOPSERVERACTION = "stopserver";
	
	public static String SETPROXYACTION = "setproxy";
	
	public static String UNSETPROXYACTION = "unsetproxy";
	
	public static String ALTKEYDOWNACTION = "altkeydown";
	
	public static String ALTKEYUPACTION = "altkeyup";
	
	public static String BREAKACTION = "break";
	
	public static String JTYPEACTION = "jtype";

	/**
	 * Acording the type to generate action.
	 * @param type String that defines the type of the action.
	 * @param target String that defines the graphical elements operated by action.
	 * @param value String that defines the value of the action.
	 * @param delay String that defines the delay time after the action finished.
	 * @param offset String that defines the offset of the graphical elements.
	 * @return Action 
	 */
	public static BaseAction createAction(ActionScript action) {

		if(!ConfigUtil.getInstance().isRegisteredAction(action.getType().toUpperCase())){
			Util.warn("The action type of "+ action.getType()+" is not registered.");
			return null;
		}
		BaseAction result = null;
		result = ConfigUtil.getInstance().getRegisterAction(action);
		
		if(result == null){			
			Util.error("invalid action type:"+action.getType());
			System.exit(-1);
		}
		return result;
	}

}
